package com.maxatime.utils;

import java.time.*;

import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author Mr.Zhao
 * @title:
 * @projectName phoenix
 * @description: TODO
 * @date 2021/9/1 10:38
 */
public class LocalDateTimeUtil {



//        Java8Tester java8tester = new Java8Tester();
//        java8tester.testLocalDateTime();
//    }
//
//    public void testLocalDateTime(){

        // 获取当前的日期时间
//        LocalDateTime currentTime = LocalDateTime.now();
//        System.out.println("当前时间: " + currentTime);
//        LocalDate date1 = currentTime.toLocalDate();
//        System.out.println("date1: " + date1);

    //        // 把字符串转换成LocalDateTime
//        LocalTime date5 = LocalTime.parse("20:15:30");
//        System.out.println("date5: " + date5);




    /*
    *
     * @Author Mr.Zhao
     * @Title stringConverlocalDateTime
     * @Description  把字符串转换成LocalDateTime
     * @Date 17:01 2021/9/9
     * @Param [dateString]
     * @return java.time.LocalDateTime
     **/
    public static LocalDateTime stringConverlocalDateTime(String dateString){
//        LocalDateTime time=  LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter= DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(dateString, dateTimeFormatter);

        return parse;
    }


    /*
    *
     * @Author Mr.Zhao
     * @Title localDateTimeConverString
     * @Description  把LocalDateTime转换成字符串
     * @Date 17:02 2021/9/9
     * @Param [localDateTime]
     * @return java.lang.String
     **/
    public static String localDateTimeConverString(LocalDateTime localDateTime){
//        LocalDateTime time=  LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter= DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        return localDateTime.format(dateTimeFormatter);
    }



    /*
    *
     * @Author Mr.Zhao
     * @Title DateToLocalDateTime
     * @Description   //把date类型转换成LocalDateTime
     * @Date 17:02 2021/9/9
     * @Param [date]
     * @return java.time.LocalDateTime
     **/
    public static LocalDateTime DateToLocalDateTime(Date date) {
            // TODO Auto-generated method stub
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();

            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
            return localDateTime;
    }


    /*
    *
     * @Author Mr.Zhao
     * @Title LocalDateTimeTodate
     * @Description  //把LocalDateTime类型转换成date
     * @Date 17:03 2021/9/9
     * @Param [localDateTime]
     * @return java.util.Date
     **/
    public static Date LocalDateTimeTodate(LocalDateTime localDateTime) {
//        LocalDateTime localDateTime=LocalDateTime.now();
        ZoneId zoneId = ZoneId.systemDefault();
        Date date = Date.from(localDateTime.atZone(zoneId).toInstant());
        return date;
    }



}
